﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WorkerService.Common;

namespace WorkerService
{
    public class MyWorker : IHostedService
    {
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _ = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromSeconds(5));
            var _configuration = IocManager.GetService<IConfiguration>();
            string connectionString = _configuration.GetConnectionString("MSSQL");
            return Task.CompletedTask;
        }

        public Task StopAsync(CancellationToken cancellationToken)
        {
            return Task.CompletedTask;
        }

        private void DoWork(object state)
        {
            Console.WriteLine("Running scheduled task..." + DateTime.Now);
        }
    }
}
